<?php
/**
 * login.php - login verify file
 *
 * NMIT BIT Project - Infinity - A 3D Website using WebGL & HTML5 Technology
 * Infinity Grid Version 
 * Version: 1.0 Beta 2
 *
 * Infinity - Login function test
 *
 * Author: William Liu <qzliuyuzou@gmail.com> <lyzdev@gmail.com>
 *
 * Required Server Version:
 *  PHP5 or higher
 *  MySQL 5 or higher
 *
 * Required Browser Version:
 *  Google Chrome 9 or higher
 *  Mozilla Firefox 4 Beta or higher
 *  *Apple Safari
 *
 * Copyright (c) 2011, William Liu All rights reserved.
 * Infinity is an open source 3D website project
 * Under Apache License 2.0
 * http://www.lyzsoft.cn
 * http://7cloud.wordpress.com
 *
 * Project Starting date: 9/3/2011
 * Update Date 1: 6/4/2011
 *
**/
?>

<?php  
@mysql_connect("localhost", "root","P@ssword1")               //mysql connection  
or die("Database Connection Fail!");  
@mysql_select_db("PRJ_Nova")                    //slect database 
or die("The Database is not available!");  

//get user input from index.php 
$username = $_POST['username'];  
$password = $_POST['password']; 
 
//SQL query and get session value
$query = @mysql_query("select username, user_level from users "."where username = '$username' and password = '$password'")  
or die("SQL query fail!");

//Determine whether the username and password correct
if($row = mysql_fetch_array($query))  
{  
    session_start();                            //Initialize session  
    //Determine user right/lvl, 1 and 0 is available
    if($row['user_level'] == 1 or $row['user_level'] == 0)  
    {  
        $_SESSION['username'] = $row['username'];  
        $_SESSION['user_Level'] = $row['user_level'];  
        echo '<a href="main.php" mce_href="main.php">Welcome, Click here to login</a>';  
    }  
    else                                    //if user right/lvl is invalid
    {  
        echo "User level is invalid!";  
    }  
}  
else                                        //if username or password is wrong 
{  
    echo "User name or Password wrong!";  
}  
?>  